From 7829745107cf5b4d6473162c99ae476614ea5fda Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 12 May 2006 21:09:05 +0000 Subject: [PATCH] More scragglers from last merge. --- gpsbabel/Makefile.in | 12 ++---- gpsbabel/defs.h | 18 ++++++++- gpsbabel/route.c | 10 ++--- gpsbabel/units.c | 94 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 gpsbabel/units.c diff --git a/gpsbabel/Makefile.in b/gpsbabel/Makefile.in index 8a7f66da5..75b4fbc61 100644 --- a/gpsbabel/Makefile.in +++ b/gpsbabel/Makefile.in @@ -11,11 +11,7 @@ DOCVERSION=development # VERSIONU=1_2_7 # VERSIOND=1.2.7 -# If you do not have libexpat and you have no use for reading any input -# type that is XML-ish (i.e. gpx or geocaching.com's/loc) you can uncomment -# INHIBIT_EXPAT and coment out LIBEXPAT on just to get a build working quickly. -# INHIBIT_EXPAT=-DNO_EXPAT -LIBEXPAT=@EXPAT_LIB@ # -lefence +#EXTRA_LIBS -lefence # Space is significant, because MSVC wants no space between switch and arg (-Fofoo.o) # but cc/gcc does: @@ -31,7 +27,7 @@ OPTIMIZATION=-O $(EXTRA_OPTIMIZATION) DEBUGGING=-g $(EXTRA_DEBUGGING) # add -DDEBUG_MEM to turn on memory allocation logging GBCFLAGS=$(EXTRA_CFLAGS) $(DEBUGGING) -I. -I@srcdir@/coldsync \ - $(INHIBIT_USB) $(OPTIMIZATION) @CFLAGS@ + $(OPTIMIZATION) @CFLAGS@ INSTALL_TARGETDIR=/usr/local/ # OTHER_ROOT=/opt/local # For DarwinPorts on OSX @@ -73,7 +69,7 @@ SHAPE=shapelib/shpopen.o shapelib/dbfopen.o LIBOBJS = queue.o route.o waypt.o filter_vecs.o util.o vecs.o mkshort.o \ csv_util.o strptime.o grtcirc.o vmem.o util_crc.o xmlgeneric.o \ uuid.o formspec.o xmltag.o cet.o cet_util.o fatal.o rgbcolors.o \ - inifile.o garmin_fs.o gbsleep.o \ + inifile.o garmin_fs.o gbsleep.o units.o @GBSER@ \ $(COLDSYNC) $(GARMIN) $(JEEPS) $(SHAPE) $(FMTS) $(FILTERS) OBJS = main.o globals.o $(LIBOBJS) @@ -89,7 +85,7 @@ WEB=../babelweb/ all: gpsbabel@EXEEXT@ gpsbabel@EXEEXT@: $(OBJS) - @CC@ $(CFLAGS) $(OBJS) @LIBS@ @USB_LIBS@ $(LIBEXPAT) $(OUTPUT_SWITCH)$@ + @CC@ $(CFLAGS) $(OBJS) @LIBS@ @EXPAT_LIB@ @USB_LIBS@ $(OUTPUT_SWITCH)$@ Makefile: Makefile.in config.status CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index b8fe32c5f..4eec8ca4c 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -356,8 +356,8 @@ typedef struct { double distance_meters; double max_alt; double min_alt; - double max_spd; - double min_spd; + double max_spd; /* Meters/sec */ + double min_spd; /* Meters/sec */ time_t start; /* Min time */ time_t end; /* Max time */ } computed_trkdata; @@ -552,6 +552,7 @@ typedef enum { ff_cap_read = 1, ff_cap_write = 2 } ff_cap; + #define FF_CAP_RW_ALL \ { ff_cap_read | ff_cap_write, ff_cap_read | ff_cap_write, ff_cap_read | ff_cap_write } @@ -745,6 +746,19 @@ double degrees2ddmm(double deg_val); unsigned long get_crc32(const void * data, int datalen); unsigned long get_crc32_s(const void * data); +/* + * From units.c + */ +typedef enum { + units_unknown = 0, + units_statue = 1, + units_metric =2 +} fmt_units; + +int fmt_setunits(fmt_units); +double fmt_distance(const double, char **tag); +double fmt_speed(const double, char **tag); + /* * From gbsleep.c */ diff --git a/gpsbabel/route.c b/gpsbabel/route.c index 609558c7d..cb0a4fb0f 100644 --- a/gpsbabel/route.c +++ b/gpsbabel/route.c @@ -468,8 +468,8 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) first.latitude = 0; first.longitude = 0; first.creation_time = 0; - tdata->min_alt = 999999; - + tdata->min_alt = 999999999; + tdata->max_alt = -999999999; QUEUE_FOR_EACH((queue *)&trk->waypoint_list, elem, tmp) { time_t timed; @@ -490,16 +490,16 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) dist = radtometers(gcdist(plat, plon, tlat, tlon)); /* - * Avoid that 6300 miles as we move from 0,0. + * Avoid that 6300 mile jump as we move from 0,0. */ if (plat && plon) { tdata->distance_meters += dist; } /* - * If we've moved, recompute speed. + * If we've moved as much as a meter, recompute speed. */ - if (timed) { + if (timed && (dist > 1)) { this->speed = dist / labs(timed); if (this->speed > tdata->max_spd) { tdata->max_spd = this->speed; diff --git a/gpsbabel/units.c b/gpsbabel/units.c new file mode 100644 index 000000000..0b8f93b72 --- /dev/null +++ b/gpsbabel/units.c @@ -0,0 +1,94 @@ +/* + Display scaled distances in 'local' units. + + Copyright (C) 2006 Robert Lipe, robertlipe@usa.net + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#include "defs.h" + +static int units = units_statue; + +int +fmt_setunits(fmt_units u) +{ + switch (u) { + case units_statue: + case units_metric: + units = u; + return 0; + default: + return 1; + } +} + +double +fmt_distance(const double distance_meters, char **tag) +{ + double d; + + switch (units) { + case units_statue: + d = METERS_TO_FEET(distance_meters); + if (d < 5280) { + *tag = "ft"; + } else { + d = METERS_TO_MILES(distance_meters); + *tag = "mi"; + } + break; + case units_metric: + d = distance_meters; + if (d < 1000) { + *tag = "meters"; + } else { + d = d / (double) 1000.0; + *tag = "km"; + } + break; + + default: + fatal("not done yet"); + break; + } + + return d; +} + +double +fmt_speed(const double distance_meters_sec, char **tag) +{ + double d; + + switch (units) { + case units_statue: + d = METERS_TO_MILES(distance_meters_sec) * SECONDS_PER_HOUR ; + *tag = "mph"; + break; + case units_metric: + d = distance_meters_sec * SECONDS_PER_HOUR; + *tag = "meters/hour"; + if (d > 1000.0) { + d /= 1000.0; + *tag = "km/hour"; + } + break; + default: fatal("not done yet"); + + } + return d; +} -- 2.30.2